<extend name="./public/frame.html"/>
<block name="content">
    <style>
        .layui-form-label{width: 12%;}
        .layui-input-block{margin-left: 12%;}
    </style>
    <form class="layui-form layui-form-pane1" method="post" enctype="multipart/form-data">
        <div class="layui-form-item">
            <label class="layui-form-label">所属区域</label>
            <div class="layui-input-block">
                <div class="layui-row" style="float:left;width: 200px;">
                    <div class="layui-col-xs3">
                        <div class="layui-form">
                            <div class="layui-inline">
                                <div class="layui-input-inline" style="width: 200px;margin-right: 5px;">
                                    <select name="province_id" id="province_id" lay-verify="required" lay-filter="province">
                                        <option value="">请选择省份</option>
                                        <?php foreach($provinceList as $key=>$value):?>
                                        <option value="<?php echo $value['region_id'];?>"><?php echo $value['region_name'];?></option>
                                        <?php endforeach;?>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-row" style="float:left;width: 200px;margin-left: 5px;">
                    <div class="layui-col-xs3">
                        <div class="layui-form">
                            <div class="layui-inline">
                                <div class="layui-input-inline" style="width: 200px;margin-right: 5px;">
                                    <select name="city_id" id="city_id" lay-verify="required" lay-filter="city">
                                        <option value="">请选择城市</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">加盟商名称</label>
            <div class="layui-input-block">
                <input type="text" name="franchisee_name" lay-verify="required" placeholder="请输入加盟商名称"
                       autocomplete="off" class="layui-input" style="width: 500px;">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">组织机构代码</label>
            <div class="layui-input-block">
                <input type="text" name="organization" placeholder="请输入组织机构代码"
                       autocomplete="off" class="layui-input" style="width: 500px;">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系人姓名</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="required" placeholder="请输入联系人姓名"
                       autocomplete="off" class="layui-input" style="width: 500px;">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系人电话</label>
            <div class="layui-input-block">
                <input type="text" name="phone" lay-verify="required" placeholder="请输入联系人电话"
                       autocomplete="off" class="layui-input" style="width: 500px;">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="content" placeholder="请输入备注信息" class="layui-textarea" style="width: 500px;"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="add">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script>
        layui.use(['form'], function () {
            form = layui.form;
            form.on('select(province)', function(data){
                $("#city_id").empty();
                $("#city_id").append('<option value=>请选择城市</option>');
                var province_id = data.value;
                $.ajax({
                    url:'{:url("/admin/Franchisee/cityList")}',
                    async:true,
                    //dataType:'json',
                    type:'post',
                    data:{'province_id':province_id},
                    success:function(res){
                        $("#city_id").append(res);
                        form.render('select');
                    },
                    error:function(e){
                        layer.msg('请求错误');return false;
                    }
                })
            });
            form.on('submit(add)', function(data){
                var province_id     = data.field.province_id;
                var city_id         = data.field.city_id;
                var franchisee_name = data.field.franchisee_name;
                var organization    = data.field.organization;
                var username        = data.field.username;
                var phone           = data.field.phone;
                var content         = data.field.content;
                $.ajax({
                    url:'{:url("/admin/Franchisee/franchiseeInsert")}',
                    async:true,
                    dataType:'json',
                    type:'POST',
                    data:{'province_id':province_id,'city_id':city_id,'franchisee_name':franchisee_name,'organization':organization,'username':username,'phone':phone,'content':content},
                    success:function(res){
                        if(res.code==1){
                            layer.alert(res.msg, {icon: 6},function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                window.parent.location.reload()
                            });
                        }else{
                            layer.msg(res.msg,{icon: 5});
                        }
                    }
                });
                return false;
            });
        });
    </script>
</block>
